
let baseUrl = 'http://192.168.1.188:8088'; //测试地址
// const baseUrl = 'https://www.careoe.com:8010'; // 正式地址 
// const baseUrl ='http://192.168.1.114:8088'
// const socketUrl = "wss://www.careoe.com:9092/ws"//测试地址
const socketUrl = "wss://www.cyf.careoe.com:9092/ws"// 正式地址
function POST(url, data,head) {
  var data = data || ''
  var head = head || ''
  return new Promise((resolve, reject) => {
    // wx.showLoading({
    //   title: '加载中',
    // })
    var jwt = wx.getStorageSync('jwt') ? wx.getStorageSync('jwt') : ''
    wx.request({
      url: baseUrl + url,
      header: {
        'type': 1,
        'version': 1.0,
        'jwt': jwt,
        'idempotenceToken': head
      },
      data: data,
      method: 'POST',
      success: function (res) {
        if (res.data.status == 404 || res.data.code == 300){
          wx.clearStorageSync()
          wx.switchTab({
            url: '/pages/index/index',
          })
          return false
        }
        if(res.data.code==500){
          wx.showToast({
            title: res.data.msg,
          })
        }
        if (url =='/api/memberInfo/getMemberInfo'){
          if (res.data.status == 200 && res.data.result.currentStatus=="1"){
            getApp().globalData.flag = true
            wx.switchTab({
              url: '/pages/index/index',
            })
          }
        }
        resolve(res);
      },
      fail: function (res) {
        wx.showModal({
          title: '提示',
          content: '网络请求失败,请稍后重试。',
        })
        reject(res);
      },
      complete: function () {
        // wx.hideLoading()
      }
    })
  })
}
function GET(url, data) {
  // wx.showLoading({
  //   title: '加载中',
  // })
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + url,
      data: data,
      method: 'GET',
      success: function (res) {
        resolve(res);
      },
      fail: function (res) {
        wx.showModal({
          title: '提示',
          content: '网络请求失败,请稍后重试。',
        })
        reject(res);
      },
      complete: function () {
        // wx.hideLoading()
      }
      })
  })
}
module.exports = {
  POST: POST,
  GET: GET,
  baseUrl: baseUrl,
  socketUrl: socketUrl
}
